package com.example.meitao.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.meitao.R;
import com.example.meitao.adapter.PagerMeAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 星星 on 2016/9/1.
 */
public class ShopFragment extends Fragment{
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private PagerAdapter mPagerAdapter;
    private List<Fragment> mFragment;
    private List<String> mTitle;
    private View progressBar;
    private boolean hasInited = false;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.shop_item, null);
        progressBar = view.findViewById(R.id.progressbar);
        initView(view);
        initData();
        setData();
        setListener();
        return view;
    }

    private void initView(View view) {
        mTabLayout = (TabLayout) view.findViewById(R.id.tl_tablayout_test);
        mViewPager = (ViewPager) view.findViewById(R.id.vp_tablayout_test);
    }

    private void initData() {
        mFragment = new ArrayList<>();
        mTitle = new ArrayList<>( );
        mFragment.add(new ZheKouFragment());
        mFragment.add(new HuaTiFragment());
        mTitle.add("          相关折扣          ");
        mTitle.add("          相关话题          ");
        mPagerAdapter = new PagerMeAdapter(getActivity().getSupportFragmentManager(),mFragment,mTitle);

    }

    private void setData() {
        mViewPager.setAdapter(mPagerAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void setListener() {

    }

    public void initShow() {
        if (!hasInited) {
            hasInited = true;
            progressBar.setVisibility(View.GONE);
        }
    }
}
